import { Table } from 'antd';
import type { TableProps } from 'antd/lib/table';

interface CustomTableProps<T> extends TableProps<T> {
  total: number;
  page: number;
  pageSize: number;
  setPage: (page: number) => void;
  setPageSize: (pageSize: number) => void;
}

const CustomTable = <T extends object>({
  total,
  page,
  pageSize,
  setPage,
  setPageSize,
  ...tableProps
}: CustomTableProps<T>) => {
  return (
    <Table
      pagination={{
        current: page,
        pageSize: pageSize,
        total: total,
        showTotal: (total) => `共 ${total} 条`,
        onChange: (page, pageSize) => {
          setPage(page);
          setPageSize(pageSize);
        },
        pageSizeOptions: [5, 10, 20, 50, 100],
        locale: {
          items_per_page: '条/页',
          jump_to: '跳至',
          page: '页',
          prev_page: '上一页',
          next_page: '下一页',
        },
        showSizeChanger: true,
        showQuickJumper: true,
        size: 'small',
      }}
      {...tableProps}
    />
  );
};

export default CustomTable;
